package cn.pzhu.controller.admin;

import cn.pzhu.constant.ConstantLogin;
import cn.pzhu.controller.BaseController;
import cn.pzhu.interceptor.AdminLoginInterceptor;
import cn.pzhu.services.admin.IndexServices;
import com.jfinal.aop.Before;
import com.jfinal.aop.Clear;

/**
 * Created by dongp on 2016/4/22.
 *
 * 后台首页管理
 */
//@Before(AdminLoginInterceptor.class)
public class IndexController extends BaseController {

    private IndexServices indexServices = new IndexServices();

    public void index() {
        this.render("login.jsp");
    }

    /**
     * 验证登陆
     */
    @Clear
    public void login(){
        if("post".equalsIgnoreCase(this.getRequest().getMethod())){
            String account = this.getPara("account", "");
            String password = this.getPara("password", "");

            // 验证成功后跳转
            int result = indexServices.validLogin(getRequest(),account,password);
            if(result == ConstantLogin.login_info_1){
                this.render("index/index.jsp");
            }else{
                // 返回错误信息
                this.render("login.jsp");
            }
        }else{
            this.render("login.jsp");
        }
    }
    // 登出操作
    public void logout() {
        try {
           getSession().removeAttribute("user");
        } catch (Exception e) {

        }

        this.redirect("/admin/login");
    }
}
